/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2009, Around(J2)ME				                                 **
 **   All rights reserved.                                                   **
 **                                                                          **
 **   This program and the accompanying materials are made available under   **
 **   the terms of the New BSD License which accompanies this    			 **
 **   distribution.											                 **
 **   A copy is found in the textfile LICENSE.txt							 **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Main developers:                                                       **
 **     Juri Strumpflohner		http://blog.js-development.com	             **
 **		Matthias Braunhofer		http://matthias.jimdo.com                    **
 **                                                                          **
 **  **********************************************************************  */

package org.aroundme.unittests;

import java.util.ArrayList;

import org.aroundme.model.Place;
import org.aroundme.model.XMLResponseEncoder;
import org.aroundme.unitTools.TestFixture;
import org.aroundme.utility.Constants;

public class XMLResponseEncoderTest extends TestFixture {
	private XMLResponseEncoder responseEncoder;
	
	protected void setUp() throws Exception {
		super.setUp();
		responseEncoder = new XMLResponseEncoder();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		responseEncoder = null;
	}

	public void testEncodePlacesToXML() {
		ArrayList<Place> places = xmlTestUtils.getDummyPlaces();
		String xmlString = responseEncoder.encodePlacesToXML(places);
		assertNotNull(xmlString);
		assertTrue("type should be " + Constants.DATA_PLACE, xmlString.contains("<type>" + Constants.DATA_PLACE + "</type>"));
		for (Place place : places) {
			assertTrue("Id of place", xmlString.contains("<id>" + place.getId() + "</id>"));
			assertTrue("Name of place", xmlString.contains("<name>" + place.getName() + "</name>"));
			assertTrue("Address of place", xmlString.contains("<address>" + place.getAddress() + "</address>"));
			assertTrue("User of place", xmlString.contains("<user>" + place.getUser().getLoginName() + "</user>"));
		}
	}
	
	public void testEncodeAlert(){
		String alertType = "error";
		String alertMessage = "An error has occured! The requests couldn't be fulfilled!";
		
		String xmlResponseStr = responseEncoder.encodeAlert(alertType, alertMessage);
		
		assertNotNull(xmlResponseStr);
		
		assertTrue("alertType is correct", xmlResponseStr.contains("<level>" + alertType + "</level>"));
		assertTrue("messages is correct", xmlResponseStr.contains("<message>" + alertMessage + "</message>"));
	}

}
